<?php

namespace app\common\model;

use think\Model;
use think\Db;
class record extends Model {
	function __construct() {
		parent::initialize();
	}
	
	private $md5key = '32$#@#12<M>/+_)+)mm';
	//计算事务中金额md5
	public function updateContentMd5($id){
		//amount contract_amount order_no
		$row = Db::table('affair_table')->field('contract_amount,amount,order_no')->find($id);
		if(!$row) return false;
// 		$row = ['contract_amount' => 1, 'amount' => 2, 'order_no' => 3];
		$time = time();
		$md5 = md5($this->md5key.$row['contract_amount'].$row['amount'].$row['order_no'].$time);
		$res = self::table('record')->where(['affair_id' => $id])->update(['c_code' => $md5, 'c_t' => $time]);
		if(0 == $res) self::table('record')->insert(['id' => $id, 'c_code' => $md5, 'c_t' => $time]);
		return true;
	}
	
	//计算事务评审结果
	public function updateJuryMd5($id){
		$row = Db::table('affair_table')->field('cur_step,cur_person,final_opinion')->find($id);
		if(!$row) return false;
		$time = time();
		$md5 = md5($this->md5key.$row['cur_step'].$row['cur_person'].$row['final_opinion'].$time);
		$res = self::table('record')->where(['affair_id' => $id])->update(['o_code' => $md5, 'o_t' => $time]);

		if(false === $res) self::table('record')->insert(['id' => $id, 'c_code' => $md5, 'c_t' => $time]);
		return true;
	}
}

?>